<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .nav1 {
            height: 100px;
            width: 100px;
            background-color: green;
            font-size: large;
            font-weight: 1000;
            color: #fff;
            text-align: center;
            line-height: 90px;
            user-select: none;
        }
        .nav2 {
            height: 100px;
            width: 100px;
            background-color: rgba(29, 99, 22, 0.992);
            font-size: large;
            font-weight: 1000;
            color: #fff;
            text-align: center;
            line-height: 90px;
            user-select: none;
        }
    </style>
</head>
<body>
    <nav class="nav1" id="nav-button">别点我</nav>
</body>
<script>
    //执行事件步骤：获取事件源， 注册事件， 添加事件处理程序
    let nav = document.getElementById("nav-button");
    nav.onclick = function(){
        if(nav.className==='nav1'){
            nav.className = 'nav2';
        }else{
            nav.className = 'nav1';
        }
    }
</script>
</html>